#include<reg52.h>


unsigned char keyscan()
{
  char x,y,k;
  P2=0xf0;
  if(P2!=0xf0)
  {
   switch(P2)
   {
    case 0xe0: x=3; break;
    case 0xd0: x=2; break;
    case 0xb0: x=1; break;
    case 0x70: x=0; break;
   } 
  } 
  P2=0x0f;
  if(P2!=0x0f)
  {
    switch(P2)
    {
    case 0x0e: y=0; break;
    case 0x0d: y=1; break;
    case 0x0b: y=2; break;
    case 0x07: y=3; break;
	}
  }
  k=4*x+y;
return(k);
}


void main()
{
   unsigned char tiao[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
   while(1)
   {
        P2=0xf0;                              
        while(P2!=0xf0)            
        {
            
			  P1=0x00;
			  P0=tiao[keyscan()];
     
        }
    }
}
